
//	FileBean.java
//	Model file Generated using JSONExport: https://github.com/Ahmed-Ali/JSONExport
package com.fzc.rhinooffice.module.entity;

import com.lidroid.xutils.util.LogUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;


public class FileBean{

	private AttachmentRecord[] attachmentRecord;
	private String attachmentRows;
	private String mfId;
	private String mfName;
	private String mfType;
	private String sendTime;
	private String userId;

	public void setAttachmentRecord(AttachmentRecord[] attachmentRecord){
		this.attachmentRecord = attachmentRecord;
	}
	public AttachmentRecord[] getAttachmentRecord(){
		return this.attachmentRecord;
	}
	public void setAttachmentRows(String attachmentRows){
		this.attachmentRows = attachmentRows;
	}
	public String getAttachmentRows(){
		return this.attachmentRows;
	}
	public void setMfId(String mfId){
		this.mfId = mfId;
	}
	public String getMfId(){
		return this.mfId;
	}
	public void setMfName(String mfName){
		this.mfName = mfName;
	}
	public String getMfName(){
		return this.mfName;
	}
	public void setMfType(String mfType){
		this.mfType = mfType;
	}
	public String getMfType(){
		return this.mfType;
	}
	public void setSendTime(String sendTime){
		this.sendTime = sendTime;
	}
	public String getSendTime(){
		return this.sendTime;
	}
	public void setUserId(String userId){
		this.userId = userId;
	}
	public String getUserId(){
		return this.userId;
	}
	public FileBean(){}
	/**
	 * Instantiate the instance using the passed jsonObject to set the properties values
	 */
	public FileBean(JSONObject jsonObject){
		if(jsonObject == null){
			return;
		}

		attachmentRows = jsonObject.optString("attachment_rows");
		mfId = jsonObject.optString("mf_id");
		mfName = jsonObject.optString("mf_name");
		mfType = jsonObject.optString("mf_type");
		sendTime = jsonObject.optString("send_time");
		userId = jsonObject.optString("user_id");

		try {

			JSONArray attachmentRecordJsonArray = jsonObject.optJSONArray("attachment_record");
			if(attachmentRecordJsonArray != null){
				attachmentRecord = new AttachmentRecord[attachmentRecordJsonArray.length()];
				for (int i = 0; i < attachmentRecordJsonArray.length(); i++) {
					JSONObject attachmentRecordObject = attachmentRecordJsonArray.optJSONObject(i);
					attachmentRecord[i]=new AttachmentRecord(attachmentRecordObject);
				}

			}
		}catch (Exception e){
			e.printStackTrace();
			LogUtils.e(e.toString());
			attachmentRecord = new AttachmentRecord[0];
		}
	}

	/**
	 * Returns all the available property values in the form of JSONObject instance where the key is the approperiate json key and the value is the value of the corresponding field
	 */
	public JSONObject toJsonObject()
	{
		JSONObject jsonObject = new JSONObject();
		try {
			if(attachmentRecord != null && attachmentRecord.length > 0){
				JSONArray attachmentRecordJsonArray = new JSONArray();
				for(AttachmentRecord attachmentRecordElement : attachmentRecord){
					attachmentRecordJsonArray.put(attachmentRecordElement.toJsonObject());
				}
				jsonObject.put("attachment_record", attachmentRecordJsonArray);
			}
			jsonObject.put("attachment_rows", attachmentRows);
			jsonObject.put("mf_id", mfId);
			jsonObject.put("mf_name", mfName);
			jsonObject.put("mf_type", mfType);
			jsonObject.put("send_time", sendTime);
			jsonObject.put("user_id", userId);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return jsonObject;
	}

}